/*    */ package change.org.eclipse.swt.browser;
/*    */ 
/*    */ import org.eclipse.swt.graphics.Point;
/*    */ import org.eclipse.swt.layout.FillLayout;
/*    */ import org.eclipse.swt.widgets.Display;
/*    */ import org.eclipse.swt.widgets.Shell;
/*    */ import org.mozilla.interfaces.nsIBaseWindow;
/*    */ import org.mozilla.interfaces.nsISupports;
/*    */ import org.mozilla.interfaces.nsIWebBrowser;
/*    */ import org.mozilla.interfaces.nsIWebBrowserChrome;
/*    */ import org.mozilla.interfaces.nsIWindowCreator;
/*    */ import org.mozilla.xpcom.Mozilla;
/*    */ 
/*    */ public class MozillaWindowCreator
/*    */   implements nsIWindowCreator
/*    */ {
/* 21 */   int refCount = 0;
/*    */ 
/*    */   public nsISupports queryInterface(String aIID)
/*    */   {
/* 27 */     return Mozilla.queryInterface(this, aIID);
/*    */   }
/*    */ 
/*    */   public nsIWebBrowserChrome createChromeWindow(nsIWebBrowserChrome parent, long chromeFlags)
/*    */   {
/* 33 */     if (parent == null) {
/* 34 */       throw new IllegalArgumentException("Parent cannot be null.");
/*    */     }
/*    */ 
/* 37 */     nsIWebBrowser webBrowser = parent.getWebBrowser();
/* 38 */     nsIBaseWindow baseWindow = (nsIBaseWindow)webBrowser.queryInterface("{046bc8a0-8015-11d3-af70-00a024ffc08c}");
/* 39 */     long parentNativeWindow = baseWindow.getParentNativeWindow();
/*    */ 
/* 41 */     Display display = Display.getCurrent();
/* 42 */     MozillaBrowser src = MozillaBrowser.findBrowser(parentNativeWindow);
/*    */ 	 

             MozillaBrowser browser;
/* 44 */     if ((chromeFlags & 0x20000000) != 0L)
/*    */     {
/* 53 */       final Shell shell = new Shell(src.getShell(), 67680);
/* 54 */       shell.setLayout(new FillLayout());
/* 55 */       browser = new MozillaBrowser(shell, 0);
/* 56 */       browser.addVisibilityWindowListener(new MozillaVisibilityWindowListener() {
/*    */         public void hide(MozillaWindowEvent event) { }
/*    */ 
/*    */         public void show(MozillaWindowEvent event) {
/* 60 */           if (event.location != null) shell.setLocation(event.location);
/* 61 */           if (event.size != null) {
/* 62 */             Point size = event.size;
/* 63 */             shell.setSize(shell.computeSize(size.x, size.y));
/*    */           }
/* 65 */           shell.open();
/*    */         }
/*    */       });
/* 68 */       browser.addCloseWindowListener(new MozillaCloseWindowListener() {
/*    */         public void close(MozillaWindowEvent event) {
/* 70 */           shell.close();
/*    */         }
/*    */       });
/* 73 */       return browser;
/*    */     }
/* 75 */     MozillaWindowEvent event = new MozillaWindowEvent(src);
/* 76 */     event.display = display;
/* 77 */     event.widget = src;
/* 78 */     for (int i = 0; i < src.openWindowListeners.length; ++i)
/* 79 */       src.openWindowListeners[i].open(event);
/* 80 */     browser = event.browser;
/* 81 */     if ((browser != null) && (!(browser.isDisposed()))) {
/* 82 */       browser.addressBar = ((chromeFlags & 0x40) != 0L);
/* 83 */       browser.menuBar = ((chromeFlags & 0x10) != 0L);
/* 84 */       browser.statusBar = ((chromeFlags & 0x80) != 0L);
/* 85 */       browser.toolBar = ((chromeFlags & 0x20) != 0L);
/* 86 */       return browser;
/*    */     }
/*    */ 
/* 90 */     throw new RuntimeException("Failed to create browser window.");
/*    */   }
/*    */ }
